package com.example.datastoreutils

import android.content.Context
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch

class MyViewModel(context: Context) : ViewModel() {
    private val userPreferencesManager = UserPreferencesManager(context)

    // 观察数据
    val username = userPreferencesManager.usernameFlow

    // 保存数据
    fun saveUsername(username: String) {
        viewModelScope.launch {
            userPreferencesManager.saveUsername(username)
        }
    }
}